
package Dir;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
/**
 * Created with IntelliJ IDEA.
 * User: Андрей
 * Date: 05.12.13
 * Time: 18:57
 * To change this template use File | Settings | File Templates.
 */
public class FileChooserTest
{
    public static void main(String[] args)
    {
            System.out.println("search directory:");
            Scanner pathScanner=new Scanner(System.in);
            String path=    pathScanner.next();
            File f = new File(path);
        if(f.isDirectory())
        {
            System.out.println("search string:");
            Scanner stringScanner=new Scanner(System.in);
            String str=    stringScanner.next();
            ArrayList<File> files = new ArrayList<File>(Arrays.asList(f.listFiles()));
            for(File item:files)
            {
                if(item.getName().contains(str))
                {
                    new SimpleDateFormat("dd-MM-yyyy HH-mm-ss").format(new Date(item.lastModified()));
                    if(item.isDirectory()) {
                        System.out.println("<dir> "+item.getName()+" размер "+(double)item.length()/1024+" кб, "+"дата обновления "+new SimpleDateFormat("dd-MM-yyyy HH-mm-ss").format(new Date(item.lastModified())));
                    }
                    if(item.isFile()) {
                        System.out.println("<file> "+item.getName()+" размер "+(double)item.length()/1024+" кб, "+"дата обновления "+new SimpleDateFormat("dd-MM-yyyy HH-mm-ss").format(new Date(item.lastModified())));
                    }
                }
            }
        }
        else
        {
            System.out.println("директория задана неверно!");
        }
    }
}